<template>
	<div class="nav-list" :class="headerClass">
		<ul>
			<li class="nav-link-active">
				<router-link to="/" class="nav-link nav-link-active" tag="div" :class="{ 'btn-gradient': routeName !== 'index'}">
					<span v-if="routeName !== 'index'">{{ $t('message.back') }}</span>{{ $t('message.home') }}
				</router-link>
			</li>
			<li v-for="(item, index) in nav" :key="item.class_id">
				<router-link :to="'/search?keyWord=' + item.class_name + '&id=' + item.class_id" class="nav-link" tag="div" :class="{activeItem : item.class_name === keyword}">
					{{ item.class_name }}
				</router-link>
			</li>
		</ul>
	</div>
</template>

<script>
export default {
  name: 'TheHeaderNav',
  props: {
    nav: {
      type: Array,
      default: []
    }
  },
  data () {
    return {
      routeName: ''
    }
  },
  computed: {
    headerClass () {
      if (this.routeName === 'index') {
        return 'nav-list-index'
      } else {
        return 'nav-list-other'
      }
    },
    keyword () {
      return this.$route.query.keyWord
    }
  },
  watch: {
    '$route' () {
      this.changeRouteName()
    }
  },
  methods: {
    changeRouteName () {
      if (this.$route.name === 'Index') {
        this.routeName = 'index'
      } else {
        this.routeName = 'other'
      }
    }
  },
  created () {
    this.changeRouteName()
  },
  activated () {
    this.changeRouteName()
  }
}
</script>

<style scoped>
  .activeItem {
    color: #ff600a!important;
    background: url(../../assets/images/icon_crown.png) no-repeat center 0;
  }
.nav-list {
	position: relative;
}

.nav-list ul {
	width: 1200px;
	margin: 0 auto;
	overflow: hidden;
}

.nav-list li {
	float: left;
	margin-right: 50px;
}

.nav-list li:last-child {
	margin-right: 0;
}

.nav-link {
	box-sizing: border-box;
	color: #333;
	font-size: 16px;
	cursor: pointer;
}

.nav-link:hover {
	color: #ff600a;
}

.nav-list-index {
	/*height: 60px;*/
}

.nav-list-index .nav-link-active {
	color: #ff600a;
	background: url(../../assets/images/icon_crown.png) no-repeat center 6px;
}

.nav-list-index .nav-link {
	height: 60px;
	line-height: 60px;
}

.nav-list-other {
/*	height: 40px;*/
	min-width: 1200px;
	border-bottom: 2px solid #fc912c;
}

.nav-list-other .nav-link-active {
	width: 115px;
	color: #fff;
	text-align: center;
}

.nav-list-other .nav-link {
	height: 40px;
	line-height: 40px;
}
</style>
